/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2025-07-16 23:34:16
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2025-07-17 00:08:10
 * @FilePath: /medical-companion-app/src/api/service.api.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { request, METHOD } from '@/service/http.service'

import { ipc } from '@/ipcRenderer'

export function GPIOTest(data) {
  return ipc
    .invoke('GPIO_TEST', {
      ...data,
      type: data?.type === 'INPUT' ? 0 : 1
    })
    .then((result) => {

      const res =  {
        number: result.number,
        value: result.state,
        reaction:
          data?.type === 'INPUT'
            ? result.state !== undefined
            : data.number === result.number && data.state === result.state
      }


      return res
    })
    .catch(() => {
      return {
        number: data.number,
        state: null,
        value: null,
        reaction: false,
        status: false
      }
    })
}

export function RS422Test(data) {
  return ipc
    .invoke('RS422_TEST', data)
    .then((result) => {
      console.log('result---->', result)
      return {
        number: result.number,
        value: result.state,
        reaction: data.number === result.number && data.state === result.state
      }
    })
    .catch(() => {
      return {
        number: data.number,
        value: null,
        reaction: false
      }
    })
}



export function NVRAMTest(data) {

  return ipc
    .invoke('NVRAM_TEST', data)
    .then((result) => {
      console.log('result---->', result)
      return result
    })

}


export function DDRTest(data) {

  return ipc
    .invoke('DDR_TEST', data)
    .then((result) => {
      console.log('result---->', result)
      return result
    })

}
